package com.zfp.hs.service;

import com.zfp.core.service.BaseService;
import com.zfp.hs.dao.HospitalDao;
import com.zfp.hs.entity.Hospital;
import com.zfp.sys.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Repository("hospitalService")
public class HospitalService extends BaseService<Hospital> {
	@Autowired
	private HospitalDao hospitalDao;

    public boolean save(Hospital hospital){
        int row = 0;
        if(hospital.getId() != null){
            row=hospitalDao.update(hospital);
        }else{
            row = hospitalDao.insert(hospital);
        }
        boolean flag=row>=1?true:false;
        return flag;
    }

    public boolean deleteById(Hospital hospital){
        int row = 0;
        if(hospital.getId() != null ){
            row=hospitalDao.delete(hospital);
        }
        boolean flag=row>=1?true:false;
        return flag;
    }
    @Rollback
    public boolean saveDepartment(Hospital hospital){
        int row = 0;
        if(hospital.getDepartmentid() != null){
            row=hospitalDao.update("Hospital.updateDepartment",hospital);
        }else{
            row = hospitalDao.insert("Hospital.insertDepartment",hospital);
            if(row>0){
                row = hospitalDao.insert("Hospital.insertHospitalDepartment",hospital);
            }
        }
        boolean flag=row>=1?true:false;
        return flag;
    }

    public boolean deleteDepartmentById(Hospital hospital){
        int row = 0;
        if(hospital.getDepartmentid() != null ){
            row=hospitalDao.delete("Hospital.deleteDepartment",hospital);
            if(row>0){
                row = hospitalDao.delete("Hospital.deleteHospitalDepartment",hospital);
            }
        }
        boolean flag=row>=1?true:false;
        return flag;
    }

    public boolean saveDoctorBelonged(SysUser sysUser){
        int row = 0;
        if(sysUser.getBelongedid() != null && sysUser.getBelongedid() != ""){
            row=hospitalDao.update("Hospital.saveDoctorBelonged",sysUser);
        }
        boolean flag=row>=1?true:false;
        return flag;
    }

    public boolean deleteDoctorBelonged(SysUser sysUser){
        int row = 0;
        if(sysUser.getUserId() != null){
            row=hospitalDao.update("Hospital.deleteDoctorBelonged",sysUser);
        }
        boolean flag=row>=1?true:false;
        return flag;
    }
}